package org.rency.crawler.common.enums;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.rency.crawler.common.CrawlerConstants;

/**
 * 队列
 *
 * @author: user_rcy@163.com <br>Created on 2015年12月5日
 * @version: V1.0.0
 * @since JDK 1.8
 */
public enum QueueKind {

  FETCH_QUEUE("FETCH_QUEUE", "待抓取队列", CrawlerConstants.QUEUE_FETCH_NAME),
  ;

  private String code;
  private String msg;
  private String queue;

  QueueKind(String code, String msg, String queue) {
    this.code = code;
    this.msg = msg;
    this.queue = queue;
  }

  public String getCode() {
    return this.code;
  }

  public String getMsg() {
    return this.msg;
  }

  public String getQueue() {
    return queue;
  }

  public static QueueKind get(String code) {
    if (StringUtils.isBlank(code)) {
      return null;
    }
    for (QueueKind ek : QueueKind.values()) {
      if (ek.getCode().toUpperCase().equals(code.toUpperCase())) {
        return ek;
      }
    }
    throw new IllegalArgumentException("未知的状态码:" + code);
  }

  public static String get(QueueKind method) {
    if (method == null) {
      return null;
    }
    return method.getCode();
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  }
}